#!/usr/bin/env node

const log = console.log;

//实例化buffer对象
let buf1 = Buffer.alloc(256);
buf1[0] = 0;    //初始化第一个字节为零
log('buf1 length:\n',buf1.length); //buf1的长度
log('buf1:\n',buf1);    //buf1内容

//通过循环初始化buf1每个字节
for(let i=0; i<buf1.length; i++){
  buf1[i] = i;
}
log('buf1:\n',buf1);

//切片操作
let buf2 = buf1.slice(250, 256);
log('buf2:\n',buf2);
log('buf2 length:\n',buf2.length);

//填充操作
buf2.fill(0);
log('buf2:\n',buf2);

//数组初始化buf3
let array = ['fu', 255, 88, 0xba];
let buf3 = Buffer.from(array);
log('buf3:\n',buf3);
log('buf3 length:\n',buf3.length);

//用字符串初始化buf4
let buf4 = Buffer.from('hello','utf8');
log('buf4 length:\n',buf4.length);
log('buf4:\n',buf4);

//数据复制  4复制到3
buf4.copy(buf3, 0, 0, buf3.length);
log('buf3 length:\n',buf3.length);
log('buf3:\n',buf3);
